package esiag.pds.servers;

import java.io.IOException;
import java.rmi.RemoteException;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import esiag.pds.beans.ContextSimulator;
import esiag.pds.beans.Parameters;
import esiag.pds.contextManagement.ContextManager;

public class ReplicationServer {

	 public ReplicationServer() {
		// TODO Auto-generated constructor stub			
			try {	
				//Extract Parametters
				 XmlBeanFactory factory=new XmlBeanFactory(new ClassPathResource("Parameters.xml"));
				 Parameters param=factory.getBean("parameters",Parameters.class);
				 
				 //Instanciations...
				 ContextManager cm=new ContextManager(param);
				 RMIServer server =new RMIServer(param.getPort());
				
				while(true){			
					cm.upDateContext();
					server.rebind(cm);	
					Thread.sleep(param.getUpDateContextFrequency());
				}
					
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	

	}
	
	public static void main(String[] args) throws InterruptedException {
		// TODO Auto-generated method stub		
		new ReplicationServer();
		}
}
